/*
  This file is a part of hashutils package.
  (c) 2004 Zeljko Vrba <zvrba@globalnet.hr>

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef CDT_LINE_H__
#define CDT_LINE_H__

#include <stddef.h>
#include <cdt.h>
#include <sfio.h>
#include <vmalloc.h>

/**
   @file
   Implementation of intervals: we want to be able to output e.g. 1-3 instead
   of 1,2,3. For this we maintain an ordered set of half-open intervals
   [lb, ub). Intervals NEVER overlap; they are joined in one single interval.
   A single number n is represented by the interval [n,n+1).
*/

/** Interval structure, CDT and vmalloc disciplines. */
struct interval {
	Dtlink_t _l;				/* link */
	unsigned long bounds[2];	/* 0: lower, 1: upper bound */
};

/*
  Interval discipline for containers. Note that interval must ALWAYS be
  allocated before insertion in the container. The container make and free
  functions are always set to NULL.
*/
extern Dtdisc_t Cdt_IntervalDiscipline;

Dt_t *IntervalSet_create(void);
struct interval *IntervalSet_insert1(Dt_t *dt, unsigned long n);
struct interval *IntervalSet_insert2(Dt_t *dt, unsigned long lb, unsigned long ub);

#endif /* CDT_LINE_H__ */
